package com.adhere.system.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * swagger 配置类
 *
 * @author WT
 * @date 2022/01/29 22:25:08
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {

//    @Value("${swagger.open}")
//    private boolean swaggerOpen;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
//                .enable(swaggerOpen)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .paths(PathSelectors.regex("/error.*").negate())
                .paths(PathSelectors.regex("/actuator.*").negate())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("adhere-system")
                .description("adhere-system")
                .version("0.0.1")
                .build();
    }

}
